<!DOCTYPE html>
<html lang="zh-cn">
  <head>
    <meta charset="UTF-8">
    <title>Sucha's Blog - Archive for June, 2013</title>
    <meta name="generator" content="MarkdownProjectCompositor.lua">
    <meta name="author" content="Sucha">
    <meta name="keywords" content="suchang, programming, Linux, Lua">
    <meta name="description" content="Sucha's blog">
    <link rel="shortcut icon" href="../images/ico.png">
    <link rel="stylesheet" type="text/css" href="../styles/blog.css">
    <link rel="stylesheet" type="text/css" href="../styles/prism.min.css">
    <style id="site_theme"></style>
  </head>
  <body>
    <div id="body">
      <div id="text">
	   <!-- Page published by cmark-gfm begins here --><h1>Sucha's Blog ~ Archive for June, 2013</h1>
<p><a id="p0"></a></p>
<div class="date">13年6月13日 周四 14:54</div>
<h2>[iOS] 为 App 提供打开邮件附件的支持</h2>
<p>不多说了，先描述使用场景，比如在邮件有附件，或其他 App 中有各种类型的文档，
长按文档标识系统会从底部弹出使用某某某打开，比如使用微信等等。</p>
<p>这种官方的说法是文档交互，需要这样编程处理
<a href="../https://developer.apple.com/library/ios//documentation/FileManagement/Conceptual/DocumentInteraction_TopicsForIOS/Articles/RegisteringtheFileTypesYourAppSupports.html.html#//apple_ref/doc/uid/TP40010411-SW1">Document Interaction Programming Topics for iOS</a>，简单点就是在 App 的 Info.plist 里面
添加以下就可以在系统弹出框里看到使用某某某打开了:</p>
<pre><code class="language-xml">&lt;dict&gt;
   &lt;key&gt;CFBundleTypeName&lt;/key&gt;
   &lt;string&gt;My File Format&lt;/string&gt;
   &lt;key&gt;CFBundleTypeIconFiles&lt;/key&gt;
       &lt;array&gt;
           &lt;string&gt;MySmallIcon.png&lt;/string&gt;
           &lt;string&gt;MyLargeIcon.png&lt;/string&gt;
       &lt;/array&gt;
   &lt;key&gt;LSItemContentTypes&lt;/key&gt;
       &lt;array&gt;
           &lt;string&gt;com.example.myformat&lt;/string&gt;
       &lt;/array&gt;
   &lt;key&gt;LSHandlerRank&lt;/key&gt;
   &lt;string&gt;Owner&lt;/string&gt;
&lt;/dict&gt;
</code></pre>
<p>这其实算是使用文件作为数据交换，需要指定 app 所支持的类型，这篇总览介绍
了阿婆是如何对待文件类型的 <a href="../https://developer.apple.com/library/mac//documentation/FileManagement/Conceptual/understanding_utis/understand_utis_conc/understand_utis_conc.html.html#//apple_ref/doc/uid/TP40001319-CH202-CHDHIJDE">Uniform Type Identifiers Overview</a>，系统定义的
UTI 有这些 <a href="https://developer.apple.com/library/mac/#documentation/Miscellaneous/Reference/UTIRef/Articles/System-DeclaredUniformTypeIdentifiers.html">System-Declared Uniform Type Identifiers</a>。</p>
<p>在代码里面是在 Application Delegate 的
<a href="http://developer.apple.com/library/ios/#documentation/uikit/reference/UIApplicationDelegate_Protocol/Reference/Reference.html">application:openURL:sourceApplication:annotation:</a> 响应的，添加这个函数就
可以支持了，它会在 willFinishLaunchingWithOptions 以及
didFinishLaunchingWithOptions 之后运行。</p>
<p>参考自 StackOverflow 的
<a href="http://stackoverflow.com/questions/2774343/how-do-i-associate-file-types-with-an-iphone-application">How do I associate file types with an iPhone application?</a>，噢噢噢~~~</p>
<div class="category"><a href="CategoryProgramming.html">CategoryProgramming</a> / <a href="2013-06.html#p0">Permalink</a> / <a href="https://github.com/lalawue/homepage/discussions/categories/blog" target="_blank">Discussion</a></div>
<!-- date: 2013-06-13T14:54:02+0800 -->
<!-- Page published by cmark-gfm ends here -->
  <div id="foot">2004-<script>var d = new
	Date();document.write(d.getFullYear())</script> &copy;
	Sucha. Powered by MarkdownProjectCompositor.
  </div>
  </div><!-- text -->
  <div id="sidebar">
  </div><!-- sidebar -->
  <script src="../js/prism.min.js" async="async"></script>
  <script src="../js/blog_sidebar.js"></script>
  </div> <!-- body -->
</body>
</html>